package tt.dz.egobus.servicemanager.dao.impl;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import tt.dz.egobus.servicemanager.base.dao.AbstractExtendDao;
import tt.dz.egobus.servicemanager.dao.DriverRegisterBusRelativeDao;
import tt.dz.egobus.servicemanager.entities.DriverRegisterBusRelative;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Anson
 * @date 17-3-21
 * @name 司机注册车辆
 * @since 1.0.2
 */
@Repository("driverRegisterBusRelativeDaoImpl")
public class DriverRegisterBusRelativeDaoImpl extends AbstractExtendDao<DriverRegisterBusRelative, String>
        implements DriverRegisterBusRelativeDao {
    @Override
    protected void loadInstanceClass() {
        this.setType(DriverRegisterBusRelative.class);
    }

    @Override
    public int deleteDriverRelativeByBusId(String busId) {
        String hql = " delete from DriverRegisterBusRelative where  busId=:busId ";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("busId", busId);
        Query query = this.getSession().createQuery(hql);
        query.setProperties(params);
        return query.executeUpdate();
    }

    @Override
    public int terminalBusinessDriverStatus(List<String> needHandlerDriverDbStatusActive) {
        String hql = " update  DriverRegisterBusRelative set status =:status   where  driverId in (:driverIds) and  status =:matcherStatus ";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("status", DriverRegisterBusRelative.RelativeStatus.ACTIVE.getCode());
        params.put("driverIds", needHandlerDriverDbStatusActive);
        params.put("matcherStatus", DriverRegisterBusRelative.RelativeStatus.GRAB_BUSINESS.getCode());
        Query query = this.getSession().createQuery(hql);
        query.setProperties(params);
        return query.executeUpdate();
    }
}
